Page({

  /**
   * 页面的初始数据
   */
  data: {

    latitude: 34.231274,
    longitude: 108.9584,
    markers: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //从后台请求数据
    wx.cloud.database().collection("meetingMapMsg").get({
      success: res => {
        let data = res.data;
        if(data.length > 0){
          console.log(data);
          let markers = [];
          for(let i = 0; i < data.length; i++){
            let marker = {
                id: i,
                latitude: data[i].latitude,
                longitude: data[i].longitude,
                callout: {
                  content: '会议室名称：' + data[i].name + '\n' + '详细地址：' + data[i].detail,
                  padding: 10,
                  display: 'ALWAYS',
                  textAlign: 'center',
                }
            }
            markers.push(marker)
          }  
          this.setData({
            markers:markers
          })
        }else{
          this.setData({
            markers:null
          })
        }
      }
    })
  },

  
  touchToGo(e){
    console.log(e)
    let LocationObj = e.currentTarget.dataset
    wx.openLocation({
      latitude: LocationObj.latitude,
      longitude: LocationObj.longitude,
    })
  }
})